package io.aircraft.modules.wms.controller;

import io.aircraft.common.annotation.LogOperation;
import io.aircraft.common.page.PageData;
import io.aircraft.common.utils.Result;
import io.aircraft.common.validator.ValidatorUtils;
import io.aircraft.common.validator.group.DefaultGroup;
import io.aircraft.common.validator.group.UpdateGroup;
import io.aircraft.modules.wms.dto.DvcStateDTO;
import io.aircraft.modules.wms.service.DvcStateService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 设备状态信息
 *
 * @author Cycle cycle@gmail.com
 * @since 1.0.0 2022-10-04
 */
@RestController
@RequestMapping("wms/dvc-state")
public class DvcStateController {
    @Resource
    private DvcStateService dvcStateService;

    @GetMapping("page")
    @RequiresPermissions("wms:dvc-state:page")
    public Result<PageData<DvcStateDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params) {
        PageData<DvcStateDTO> page = dvcStateService.page(params);

        return new Result<PageData<DvcStateDTO>>().ok(page);
    }

    @GetMapping("list")
    public Result<List<DvcStateDTO>> getStateList(@ApiIgnore @RequestParam Map<String, Object> params) {
        List<DvcStateDTO> data = dvcStateService.list(params);

        return new Result<List<DvcStateDTO>>().ok(data);
    }

    @PutMapping
    @LogOperation("修改")
    public Result update(@RequestBody DvcStateDTO dto) {
        System.out.println("hello"+dto);
        //效验数据
        ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);

        dvcStateService.update(dto);

        return new Result();
    }
}